﻿using GalaSoft.MvvmLight;
using RestaurantBooker.Web.Data;
using System.Collections.Generic;

namespace RestaurantBooker.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class RoomVisualizerViewModel : ViewModelBase
    {

        #region Properties

        

        /// <summary>
        /// The <see cref="Room_Tables" /> property's name.
        /// </summary>
        public const string Room_TablesPropertyName = "Room_Tables";

        private List<Room_Table> _room_tables = null;

        /// <summary>
        /// Gets the Room_Tables property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public List<Room_Table> Room_Tables
        {
            get
            {
                return _room_tables;
            }

            set
            {
                if (_room_tables == value)
                {
                    return;
                }
                _room_tables = value;                
                // Update bindings, no broadcast
                RaisePropertyChanged(Room_TablesPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="Room" /> property's name.
        /// </summary>
        public const string RoomPropertyName = "Room";

        private Room _room = null;

        /// <summary>
        /// Gets the Room property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public Room Room
        {
            get
            {
                return _room;
            }

            set
            {
                if (_room == value)
                {
                    return;
                }
                var oldValue = _room;
                _room = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(RoomPropertyName);
            }
        }
        #endregion

        #region Construcor and Cleaner
        /// <summary>
        /// Initializes a new instance of the RoomVisualizerViewModel class.
        /// </summary>
        public RoomVisualizerViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real": Connect to service, etc...

            }
        }

        public override void Cleanup()
        {
            // Clean own resources if needed
            base.Cleanup();
        }
        #endregion

        #region Methods
        internal void InitializeRoom(Web.Data.Room room)
        {
            this.Room = room;
            if (room != null)
            {
                ServiceProcessor.ServiceProcessor.Instance.GetRoomTables(Room.room_id,
                    (room_table_list) =>
                    {
                        this.Room_Tables = room_table_list;
                    });
            }
        }
        #endregion
        
    }
}